package com.gadgets.busi.bm08.controller;

import com.gadgets.busi.bm08.common.dto.*;
import com.gadgets.busi.bm08.fegin.IHdsQuestionController;
import com.gadgets.framework.annotation.RoleAuthCheck;
import com.gadgets.framework.common.constant.GadgetsConstant;
import com.gadgets.framework.common.dto.HttpBaseResp;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.FeginRequestMapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * 功能说明：
 * 软件版权：恒生电子股份有限公司
 *
 * @author xiujunqing
 * @version V202101.00.000
 * @data 2022-04-19
 * 修改记录：  修改日期          修改人员    修改说明
 * 2022-04-19  xiujunqing   创建文件
 */
@SuppressWarnings("rawtypes")
@RestController
@RequestMapping(value = "/bm08")
public class GdagetsBm08Fork {

    @Autowired
    private IHdsQuestionController hdsQuestionController;

    /**
     * 新建题目
     * @param request           请求信息
     * @param response          应答信息
     * @param questionAddDTO    题目信息
     * @return                  新增结果
     * @throws GadgetsServiceException  异常信息
     */
    @RoleAuthCheck
    @RequestMapping(value = "/addQuestion.do")
    public HttpBaseResp addTestQuestion(HttpServletRequest request, HttpServletResponse response, QuestionAddDTO questionAddDTO) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(questionAddDTO, requestParam);
        return hdsQuestionController.addTestQuestion(requestParam);
    }

    /**
     * 查询题目ID列表
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                      查询条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(value = "/selectQstId.do")
    public HttpBaseResp<Long> selectQuestionIdList(HttpServletRequest request, HttpServletResponse response, QuestionQueryDTO queryDTO) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(queryDTO, requestParam);
        return hdsQuestionController.selectQuestionIdList(requestParam);
    }

    /**
     * 根据ID查询题目、选项、答案信息
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                      查询条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck(userType = {GadgetsConstant.USER_TYPE.SYS_MANAGER})
    @RequestMapping(value = "/selectQstById.do")
    public HttpBaseResp<QuestionResultDTO> selectQuestionInfoById(HttpServletRequest request, HttpServletResponse response, QuestionQueryDTO queryDTO) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(queryDTO, requestParam);
        return hdsQuestionController.selectQuestionInfoById(requestParam);
    }

    /**
     * 根据ID查询题目、选项、答案信息
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                      查询条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(value = "/selectQstByIdNoAnswer.do")
    public HttpBaseResp<QuestionResultDTO> selectQuestionInfoByIdNoAnwser(HttpServletRequest request, HttpServletResponse response, QuestionQueryDTO queryDTO) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(queryDTO, requestParam);
        return hdsQuestionController.selectQuestionInfoByIdNoAnwser(requestParam);
    }

    /**
     * 查询题目汇总信息
     * @param request                       网络请求
     * @param response                      网络应答
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(value = "/selectQstTotal.do")
    public HttpBaseResp<QuestionTotalDTO> selectQuestionTotal(HttpServletRequest request, HttpServletResponse response) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        return hdsQuestionController.selectQuestionTotal(requestParam);
    }

    /**
     * 根据维度生成题目
     * @param request                       请求信息
     * @param response                      应答信息
     * @param generateDto                   维度条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(value = "/randomTopicGeneration.do")
    public HttpBaseResp<String> randomTopicGeneration(HttpServletRequest request, HttpServletResponse response, QuestionGenerateDTO generateDto) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(generateDto, requestParam);
        return hdsQuestionController.randomTopicGeneration(requestParam);
    }

    /**
     * 根据题目序号导出
     * @param request                       请求信息
     * @param response                      应答信息
     * @param checkDto                      维度条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(value = "/randomTopicExport.do")
    public String randomTopicExport(HttpServletRequest request, HttpServletResponse response, CheckGenerateDTO checkDto) throws GadgetsServiceException{
        HashMap<String ,Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(checkDto, requestParam);
        return hdsQuestionController.randomTopicExport(requestParam);
    }

}
